package com.bj.dz.service.impl;

import com.bj.dz.entity.CorrespondIndoorEquipment;
import com.bj.dz.mapper.CorrespondIndoorEquipmentMapper;
import com.bj.dz.service.CorrespondIndoorEquipmentService;
import com.bj.dz.util.Constants;
import com.bj.dz.util.EmptyUtils;
import com.bj.dz.util.Page;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

@Slf4j
@Service
public class CorrespondIndoorEquipmentServiceImpl implements CorrespondIndoorEquipmentService {

    @Resource
    private CorrespondIndoorEquipmentMapper correspondIndoorEquipmentMapper;

    public CorrespondIndoorEquipment getCorrespondIndoorEquipmentById(Integer id){
        return correspondIndoorEquipmentMapper.getCorrespondIndoorEquipmentById(id);
    }

    public List<CorrespondIndoorEquipment>	getCorrespondIndoorEquipmentListByMap(Map<String,Object> param){
        return correspondIndoorEquipmentMapper.getCorrespondIndoorEquipmentListByMap(param);
    }

    public Integer getCorrespondIndoorEquipmentCountByMap(Map<String,Object> param){
        return correspondIndoorEquipmentMapper.getCorrespondIndoorEquipmentCountByMap(param);
    }

    @Transactional
    public boolean addCorrespondIndoorEquipment(CorrespondIndoorEquipment correspondIndoorEquipment){
            return correspondIndoorEquipmentMapper.insertCorrespondIndoorEquipment(correspondIndoorEquipment)>0?true:false;
    }

    @Transactional
    public boolean modifyCorrespondIndoorEquipment(CorrespondIndoorEquipment correspondIndoorEquipment){
        return correspondIndoorEquipmentMapper.updateCorrespondIndoorEquipment(correspondIndoorEquipment)>0?true:false;
    }

    @Transactional
    public boolean deleteCorrespondIndoorEquipmentById(Integer id){
        return correspondIndoorEquipmentMapper.deleteCorrespondIndoorEquipmentById(id)>0?true:false;
    }

    public Page<CorrespondIndoorEquipment> queryCorrespondIndoorEquipmentPageByMap(Map<String,Object> param, Integer pageNo, Integer pageSize){
        Integer total = correspondIndoorEquipmentMapper.getCorrespondIndoorEquipmentCountByMap(param);
        pageNo = EmptyUtils.isEmpty(pageNo) ? Constants.DEFAULT_PAGE_NO : pageNo;
        pageSize = EmptyUtils.isEmpty(pageSize) ? Constants.DEFAULT_PAGE_SIZE : pageSize;
        Page page = new Page(pageNo, pageSize, total);
        param.put("beginPos", page.getBeginPos());
        param.put("pageSize", page.getPageSize());
        List<CorrespondIndoorEquipment> correspondIndoorEquipmentList = correspondIndoorEquipmentMapper.getCorrespondIndoorEquipmentListByMap(param);
        page.setRows(correspondIndoorEquipmentList);
        return page;
    }

}
